const { ccclass, property } = cc._decorator;
import MyEnums from '../MyEnums';

class _ScoreAward {
    ScoreType: number = 0;
    ScoreValue: number = 0;
}

@ccclass
export default class LevelTaskControl extends cc.Component {
    @property([cc.Label])
    tasks: cc.Label[] = [];
    Scores: _ScoreAward[] = [];
    skillString = "击杀怪兽#个";
    hurtString = "受伤不超过#次";
    timeString = "耗时不超过#秒";

    onLoad() {
        this.showStr();
    }

    showStr() {
        this.Scores = gameHelper.getInstance().getLevelParam().ScoreAward;
        let ii = 0;
        this.Scores.forEach(element => {
            if (ii < this.tasks.length) {
                switch (element.ScoreType) {
                    case MyEnums.ScoreType.time:
                        this.replaceStr(this.timeString, element.ScoreValue, this.tasks[ii]);
                        break;
                    case MyEnums.ScoreType.hurt:
                        this.replaceStr(this.hurtString, element.ScoreValue, this.tasks[ii]);
                        break;
                    case MyEnums.ScoreType.skill:
                        this.replaceStr(this.skillString, element.ScoreValue, this.tasks[ii]);
                        break;
                }
            }
            ii++;
        });
    }
    replaceStr(str: string, num: number, label: cc.Label) {
        label.string = str.replace("#", num.toFixed(0))
    }
}
